<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% page_section ||= nil %>
<div class="section <%= "read_only" if (page_section && (page_section["attachment_id"] || page_section["submission_id"])) %>" id="page_section_<%= idx %>">
  <a href="#" class="move_link no-hover" title="{{#t}}Drag to rearrange sections{{/t}}"><%= image_tag "move.png", :alt => t('Drag to rearrange sections') %></a>
  <div class="section_type_name">
    <% if !page_section || page_section["section_type"] == "rich_text" %>
      {{#t}}Rich Text Content{{/t}}
    <% elsif page_section["section_type"] == "html" %>
      {{#t}}HTML/Embedded Content{{/t}}
    <% elsif page_section["section_type"] == "submission" %>
      {{#t}}Course Submission{{/t}}
    <% elsif page_section["section_type"] == "attachment" %>
      {{#t}}Image/File Upload{{/t}}
    <% end %>
  </div>
  <div class="links">
    <a href="#" class="delete_page_section_link no-hover" title="{{#t}}Delete this section{{/t}}">{{> icons/trash}}</a>
  </div>
  <div class="section_content">
    <% if page_section %>
      <% if !page_section["section_type"] || page_section["section_type"] == "rich_text" || page_section["section_type"] == "html" %>
        <%= page_section["content"] ? raw(page_section["content"]) : t('rich_text.default_content', "Nothing Entered Yet") %>
      <% elsif page_section["section_type"] == "attachment" %>
        <div style="text-align: center;" class="attachment">
          <% attachment = @portfolio.user.attachments.find(page_section["attachment_id"]) %>
          <% if attachment && attachment.content_type.match(/\Aimage/) %>
            <a href="<%= eportfolio_entry_view_file_path(@portfolio, @page, attachment.uuid) %>" class="no-hover"><%= image_tag eportfolio_entry_view_file_path(@portfolio, @page, attachment.uuid), :alt => attachment.display_name %></a>
          <% elsif attachment %>
            <a href="<%= eportfolio_entry_view_file_path(@portfolio, @page, attachment.uuid) %>">
              <%= t('links.download_attachment', "Click here to Download *%{attachment}*",
                    :attachment => attachment.display_name,
                    :wrapper => '<span class="filename">\1</span>') %>
            </a>
          <% end %>
        </div>
      <% elsif page_section["section_type"] == "submission" %>
        <% submission = @portfolio.user.submissions.where(id: page_section["submission_id"]).first if page_section["submission_id"].present? %>
        <% if submission %>
          <iframe class="submission_preview" src="<%= eportfolio_entry_preview_submission_path(@portfolio, @page, submission.id) %>" style="border: 1px solid #aaa; width: 100%; height: 300px; display: block; margin-left: auto; margin-right: auto;" title="<%= t("%{assignment} preview", :assignment=> submission.assignment.title) %>">
          </iframe>
        <% end %>
      <% end %>
    <% end %>
  </div>
  <div style="display: none;">
    <span class="section_type"><%= (page_section["section_type"] || "rich_text") rescue "rich_text" %></span>
    <span class="attachment_id"><%= (page_section["attachment_id"] || nbsp) rescue nbsp %></span>
    <span class="submission_id"><%= (page_section["submission_id"] || nbsp) rescue nbsp %></span>
  </div>
</div>
